<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        *{
            margin: 0;
            padding: 0;
        }
        .parent{
            border: 2px solid #333;
            position: relative;
            height: 40px;
        }
        .test{
            width: 40px;
            height: 40px;
            background-color: rgb(255, 0, 43);
            /*1.  */
            /* margin: 0 auto; */
            /* 2.  */
            /* margin: 12% 50%;
            transform: translate(12%,-50%); */
            /* 3. */
            position: absolute;
            left: 50%;
            height: 40px;
        }
    </style>
</head>
<body>
    <div class="parent">
        <div class="test">

        </div>
    </div>
</body>
</html>